package com.zy.mc_module.ui.main;

import android.text.Html;
import android.webkit.WebView;
import android.widget.Space;
import android.widget.TextView;

import com.zy.mc_module.R;
import com.zy.mc_module.base.BaseActivity;
import com.zy.mc_module.mvp.bean.ProtocolBean;
import com.zy.mc_module.mvp.bean.UserBean;
import com.zy.mc_module.mvp.contract.LoginContract;
import com.zy.mc_module.mvp.presenter.LoginPresenter;
import com.zy.mc_module.utils.StatusBarUtil;
import com.zy.mc_module.utils.StringsUtils;
import com.zy.mc_module.view.CustomHeadLayout;
import com.zy.mc_module.utils.retrofit.error.ThdException;
import com.zy.mc_module.view.MyWebView;

import butterknife.BindView;

/**
 * Created on 19/1/14
 * 协议
 */
public class AgreementActivity extends BaseActivity<LoginContract.View, LoginPresenter> implements
        LoginContract.View {
    @BindView(R.id.statusBar)
    Space statusBar;
    @BindView(R.id.customhead)
    CustomHeadLayout customhead;
    @BindView(R.id.agreement_con)
    MyWebView tv_con;

    private String title = "注册协议", con;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_agreement;
    }

    @Override
    protected LoginPresenter createPresenter() {
        return new LoginPresenter();
    }

    @Override
    protected void initView() {
        StatusBarUtil.setImmersiveStatusBar(this);
        StatusBarUtil.setStatusHeight(context, statusBar);
        con = getIntent().getStringExtra("articleProtocolType");
        if ("14".equals(con))
        {
            title = "隐私协议";
        }
        //----
        customhead.setText(title);
        reloadData();
    }

    @Override
    protected void reloadData() {
        super.reloadData();
        if (con.equals("14")){
            tv_con.loadUrl("http://h5.test.wanminzg.cn/#/pages/privteRule");
        }
    }

    @Override
    protected void initListener() {
        customhead.setLeftClickListener(view -> finish());
    }

    @Override
    public void onGetCodeSuccess(String success) {

    }

    @Override
    public void onLoginSuccess(UserBean userBean) {

    }

    @Override
    public void onSuccess(boolean isSuc) {

    }

    @Override
    public <T> void onSuccess(T t, int type) {
        if (type == 2) {
            ProtocolBean protocolBean = (ProtocolBean) t;
            if (!StringsUtils.isEmpty(protocolBean)) {
                //tv_con.setText(Html.fromHtml(protocolBean.content == null ? "" : protocolBean.content));
            }
        }
    }

    @Override
    public void onError(ThdException error) {

    }
}
